const app = getApp()

const quote = app.globalData.quote;
const path = quote.paths;
const Authorize = quote.Authorize;


var template = require('../../../template/template.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow:false,
    hidePop: true,
    isAuthorize:false

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    app.globalData.template.tabbar("tabBar", 1, this)//0表示第一个tabbar
   

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that=this
    

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this
    if (app.globalData.userInfo) {
      console.log('授权了')
      that.setData({
        isShow: true,
      })
    } else {
      console.log('还没授权')

      that.setData({
        isShow: false,
      })
    }
    that.setData({
      hidePop: true
    })
    if (app.globalData.IsAuthorization){
      console.log('授权页面已经授权')
      that.setData({
        isAuthorize:true
      })
    }else{
      console.log('授权页面还没授权')
      that.setData({
        isAuthorize: false
      })
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
 
  bindgetuserinfo(params){
  
    var that=this
    var userObj = params.detail;
    var getUserInfo = userObj.errMsg.split(':');
    if (getUserInfo[1] != 'ok') {

      Authorize.checkUserInfo(function (res) {
        if (!res) {
          that.setData({
            hidePop: false,
            isShow: false
          })
        } else {
          that.setData({
            hidePop: true,
            isShow: true
          })
        }
      }) //进入授权流程
      return
     

    }
    else{
      app.globalData.userInfo = userObj.userInfo; //用户信息存入全局
      wx.setStorage({
        key: 'userInfo',
        data: userObj.userInfo,
        success: function (res) {
          console.log('用户信息存入缓存成功', res)
        }
      })
      that.setData({
        isShow: true
      })
    }
  },
  gotoUserNotes:function(){
    wx.navigateTo({
      url: '/'+path.userNotes,
    })
  },
  gotoPersonal:function(){
    wx.navigateTo({
      url: '/'+path.personalData,
    })
  },


  gotoAuthorize:function(){
    console.log(app.globalData.isAuthorize)
    var that=this
    if(!that.data.isAuthorize){
      wx.navigateTo({
        url: '/' + path.authorize,
      })
    }else{
      wx.navigateTo({
        url: '/' + path.authorizeResult,
      })
    }
  
  }
})